import { Component, OnInit } from '@angular/core';
import { ApiService } from '../../../../providers/ApiPro.service';
import { HybConfirmSendOutGoodsDto, HybReviewDispatchOrderDto, HybSendOutGoodsInfoDto } from '../HuoCustmp.model';
import { NzModalService } from 'ng-zorro-antd';
import { ActivatedRoute, Router, RouterLink, RouterModule } from '@angular/router';


@Component({
  selector: 'app-HuoCusCarInfo',
  templateUrl: './HuoCusCarInfo.component.html',
  styleUrls: ['./HuoCusCarInfo.component.scss']
})
export class HuoCusCarInfoComponent implements OnInit {
  public data: HybSendOutGoodsInfoDto = new HybSendOutGoodsInfoDto();
  public isoilCardPay: boolean;
  public isbankCardTransfer: boolean;
  public showCheck: boolean;
  public checkOrder: HybReviewDispatchOrderDto = new HybReviewDispatchOrderDto();
  public sendOutGood: HybConfirmSendOutGoodsDto = new HybConfirmSendOutGoodsDto();
  constructor(
    public apiService: ApiService,
    private route: ActivatedRoute,
    private confirmServ: NzModalService,
    private router: Router,
    
  ) { }

  ngOnInit() {
    this.getId();
  }

   getId(){
     this.route.params.subscribe((params) => {
            this.load(params['id']);
            if(params['edit'] == 'edit' ){
              this.showCheck = true;
            }// 通过这个方法来判断是否为审核
        });

  }


  load(id){
    let url = "finddispatchorderdetail"
    this.apiService.get(url,{"dispatchOrderId":id})
      .then(res =>{
        console.log(res);
        this.data = res.result;
      })
  }
  
  clearSend(){
    if(!this.isoilCardPay){
      this.sendOutGood.oilCardPay = null;
    }
    if(!this.isbankCardTransfer){
      this.sendOutGood.bankCardTransfer = null;
    }
  }

  CheckSend(){
    let url ="confirmsendoutgoods";
    this.checkOrder.dispatchOrderId = this.data.dispatchOrderId;
    this.apiService.post(url,this.checkOrder)
      .then(res =>{
        if(res.result){
          this.success();
        }else{
          this.error(res.errMsg);
        }
      })
  }

  save(){
    let url = "edittransportOrder";
    this.sendOutGood.dispatchOrderId = this.data.dispatchOrderId;
    console.log(this.sendOutGood);
    this.apiService.post(url,this.sendOutGood)
      .then(res =>{
        console.log(res);
        if(res.result){
          this.succeSave()          
        }else{
          this.error(res.errMsg);
        }
      }).catch(err =>{
        this.error(err);
      })
  }
  
  success(){
    let self = this;
      this.confirmServ.success({
      title: '成功',
      content: '派单审核成功',
      okText:'完毕',
      onOk() {
      },
    });
  }

  succeSave(){
    let self = this;
      this.confirmServ.success({
      title: '成功',
      content: '预付款成功',
      okText:'完毕',
      onOk() {
        self.router.navigateByUrl("layout/cus/car");        
      },
    });
  }

  error(err) {
    this.confirmServ.error({
      title: '错误',
      content: err,
      okText:'返回'
    });
  }

}
